package com.yhy;

import com.yhy.wxzn.common.utils.PlcGetByte;
import com.yhy.wxzn.wcs.device.netty.bean.ResultData;

/**
 * @Auther: 97354
 * @Date: 2023/11/21 17:12
 * @Description: XJHelper
 * @Version 1.0.0
 */
public class XJHelper {
    public static void main(String[] args) {
        HslCommunication.XJHelper xjHelper = new HslCommunication.XJHelper("127.0.0.1",502,(byte) 1);
        xjHelper.connect("127.0.0.1");
        byte[] bytes = new byte[8];
        //目标站
        bytes[0] = (byte) ((1002 >> 8) & 0xFF);
        bytes[1] = (byte) ((1002) & 0xFF);
        //任务类型
        bytes[2] = (byte) ((1 >> 8) & 0xFF);
        bytes[3] = (byte) ((1) & 0xFF);
        //任务号
        bytes[4] = (byte) ((10000 >> 24) & 0xFF);
        bytes[5] = (byte) ((10000 >> 16) & 0xFF);
        bytes[6] = (byte) ((10000 >> 8) & 0xFF);
        bytes[7] = (byte) (10000 & 0xFF);
        xjHelper.writeBytes("D21",bytes);
        ResultData resultData = xjHelper.readBytes("D21",12);
        if (resultData.isSuccess()) {
            byte[] dataValue = (byte[]) resultData.getValue();
            int target = PlcGetByte.bytesToInt16Hight2(dataValue, 0);
            int taskType = PlcGetByte.bytesToInt16Hight2(dataValue, 2);
            int taskNo = PlcGetByte.bytesToInt32Hight(dataValue, 4);
            int getFinish = PlcGetByte.bytesToInt16Hight2(dataValue, 8);
            int putFinish = PlcGetByte.bytesToInt16Hight2(dataValue, 10);
            System.out.println("[target]:"+target);
            System.out.println("[taskType]:"+taskType);
            System.out.println("[taskNo]:"+taskNo);
            System.out.println("[getFinish]:"+getFinish);
            System.out.println("[putFinish]:"+putFinish);

        }
    }
}
